<template>
    <div class="row">
        <div class="col-4 mb-4" v-for="item in columnList" :key="item._id">
            <div class="card h-100 shadow-sm">
                <div class="card-body text-center">
                    <img
                        class="card-img-top rounded-circle border border-light my-3"
                        :src="item.avatar && item.avatar.url"
                        :alt="item.title"
                    />
                    <h5 class="card-title">{{ item.title }}</h5>
                    <p class="card-text text-left">{{ item.description }}</p>
                    <router-link :to="`/columnDetail/${item._id}`" class="btn btn-outline-primary"
                        >进入专栏</router-link
                    >
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts">
import { computed, defineComponent, PropType } from "vue";
import { ColumnProps } from "@/store";
export default defineComponent({
    props: {
        list: {
            type: Array as PropType<ColumnProps[]>, //构造函数断言为类型得加PropType传入泛型
            required: true,
        },
    },
    setup(props) {
        const columnList = computed(() => {
            return props.list.map(item => {
                if (item.avatar) {
                    return {
                        ...item,
                        avatar: {
                            ...item.avatar,
                            url: `${item.avatar.url}?x-oss-process=image/resize,m_fixed,h_50,2_50`,
                        },
                    };
                } else {
                    return { ...item, avatar: { url: require("@/assets/logo.png") } };
                }
            });
        });
        return {
            columnList,
        };
    },
});
</script>

<style scoped lang="scss">
.card-body{
    img{
        width: 50px;
        height: 50px;
    }
}
</style>
